using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Backend.JYD.AModel.Models.Mapping
{
    public class CodeInfoMap : EntityTypeConfiguration<CodeInfo>
    {
        public CodeInfoMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.TypeCode)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Code)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Remark)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("CodeInfo");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.TypeCode).HasColumnName("TypeCode");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Sort).HasColumnName("Sort");
            this.Property(t => t.Remark).HasColumnName("Remark");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.UpdateTime).HasColumnName("UpdateTime");
            this.Property(t => t.OpId).HasColumnName("OpId");

            // Relationships
            this.HasRequired(t => t.CodeType)
                .WithMany(t => t.CodeInfoes)
                .HasForeignKey(d => d.TypeCode);

        }
    }
}
